package com.example.demo.service.impl;

import com.example.demo.dao.Company;
import com.example.demo.mapper.CompanyInfoMapper;
import com.example.demo.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {

    private final CompanyInfoMapper companyInfoMapper;

    public CompanyServiceImpl(CompanyInfoMapper companyInfoMapper) {
        this.companyInfoMapper = companyInfoMapper;
    }

    @Override
    public Boolean addCompanyInfo(Company company) {
        try {
            companyInfoMapper.save(company);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public Boolean updateCompanyInfo(Company company) {
        //执行mapper里的更新语句
        try {
            companyInfoMapper.save(company);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Company selectCompanyInfoByCCode(String code) {

        System.out.println(companyInfoMapper.findByCompanyCode(code));
        return companyInfoMapper.findByCompanyCode(code);
    }


    @Override
    public List<Company> selectAllCompanyInfo() {
        return companyInfoMapper.findAll();
    }

    @Override
    public Integer deleteCompanyInfoByCCode(String code) {

        return companyInfoMapper.deleteByCompanyCode(code);
    }

    @Override
    public List<Company> findCompanyByIsDel(Integer isDel) {
        return companyInfoMapper.findCompanyByIsDel(isDel);
    }
}
